import request from '@/utils/request'

export function getPages(params) {
  return request({
    url: '/sys/user/getPage',
    method: 'get',
    params
  })
}

export function getUserById(id) {
  return request({
    url: `/sys/user/getById`,
    method: 'get',
    params: {
      id
    }
  })
}

export function userAdd(data) {
  return request({
    method: 'post',
    url: '/sys/user/saveUser',
    data: {
      ...data
    }
  })
}

export function userUpdate(data) {
  return request({
    method: 'post',
    url: '/sys/user/editUser',
    data: {
      ...data
    }
  })
}

export function userDel(id) {
  return request({
    method: 'get',
    url: '/sys/user/deleteUser',
    params: {
      id
    }
  })
}

export function getUserRole(id) {
  return request({
    method: 'get',
    url: '/sys/user/getRoleList',
    params: {
      userId: id
    }
  })
}

export function updateUserRole(params) {
  // return request({
  //   method: 'get',
  //   url: '/sys/user/updateRole',
  //   params
  // })
  return request({
    method: 'post',
    url: '/sys/user/updateRole',
    data: params
  })
}

export function getUserFirm(userId, ids) {
  return request({
    method: 'get',
    url: '/sys/user/updateRole',
    params: {
      userId,
      ids
    }
  })
}

export function updatePassword(params) {
  return request({
    method: 'post',
    url: '/sys/user/changePassword',
    data: {
      ...params
    }
  })
}

export function reUserPassword(id) {
  return request({
    method: 'post',
    url: '/sys/user/resetPassword',
    data: {
      userid: id
    }
  })
}

export function userUpdateDisabled(ids, enable) {
  let _ids = []
  if (Array.isArray(ids)) _ids = ids
  else _ids = [ids]
  return request({
    method: 'get',
    url: '/sys/user/changeStatus',
    params: {
      ids: _ids.join(','),
      enable
    }
  })
}

export function updateUserOrgan(params) {
  return request({
    method: 'post',
    url: '/sys/user/updateOrgan',
    data: params
  })
}

export function getLeader() {
  return request({
    method: 'get',
    url: '/sys/user/getLeader'
  })
}
